package com.cow.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cow.mapper.GoodMapper;
import com.cow.pojo.Good;
import com.cow.pojo.GoodExample;
import com.cow.service.GoodService;

/**
 * @author 光环and鬼泣
 * @version 2018年5月30日 上午10:34:05
 */
@Service("goodService")
public class GoodServiceImpl implements GoodService {

	@Autowired
	private GoodMapper goodMapper = null;

	@Override
	public List<Good> getGoodList() throws Exception {
		GoodExample example = new GoodExample();
		GoodExample.Criteria criteria = example.createCriteria();
		example.setOrderByClause("good_addtime desc");
		criteria.andGoodIdIsNotNull();
		List<Good> goodList = goodMapper.selectByExample(example);
		return goodList;
	}

	@Override
	public List<Good> searchGood(String value) throws Exception {
		GoodExample example = new GoodExample();
		GoodExample.Criteria criteria = example.createCriteria();
		criteria.andGoodNameLike("%" + value + "%");
		List<Good> goodList = goodMapper.selectByExample(example);
		return goodList;
	}

	@Override
	public int insertGood(Good good) throws Exception {
		int result = goodMapper.insert(good);
		return result;
	}

	@Override
	public int deleteGood(String goodId) throws Exception {
		int result = goodMapper.deleteByPrimaryKey(goodId);
		return result;
	}

	@Override
	public Good getGoodDetail(String goodId) throws Exception {
		Good good = goodMapper.selectByPrimaryKey(goodId);
		return good;
	}

}
